import java.util.Arrays;

public class NM1 {
    //归并排序；
    public static void guiBing(int[] array){
        guiBingSon(array,0,array.length-1);
    }
    public static void guiBingSon(int[] array,int left,int right){
        //递归退出条件；
        if(left>=right){
            return ;
        }
        //进行分解操作；
        int mid =(left+right)/2;
        guiBingSon(array,left,mid);
        guiBingSon(array,mid+1,right);
        //进行合并操作；
        heBing(array,left,mid,right);
    }
    public static void heBing(int[] array,int left,int mid,int right){
        int s1=left;
        int e1=mid;
        int s2=mid+1;
        int e2=right;
        int k=0;
        int[] temp=new int[right-left+1];
        while(s1<=e1&&s2<=e2){
            if(array[s1]<=array[s2]){
                temp[k++]=array[s1++];
            }else{
                temp[k++]=array[s2++];
            }
        }
        while(s1<=e1){
            temp[k++]=array[s1++];
        }
        while(s2<=e2){
            temp[k++]=array[s2++];
        }
        //归并完成进行存放到原来的数组中去；
        for(int i=0;i<k;i++){
            array[i+left]=temp[i];
        }
    }
    public static void main(String[] args){
        int[] array={23,11,22,10,2,3,4,1,3,4};
        guiBing(array);
        System.out.println(Arrays.toString(array));
    }
}
